package com.tcs.test.print;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;


public class Print1 {
	
	private final Logger logger = LoggerFactory.getLogger(Print1.class);

	@Test
	public void say1() {
		List<Integer> list = Lists.newArrayList();
		for (int i = 0; i < 100; i++) {
			list.add(i);
		}
		
		int du = 10;
		int count = list.size() / du + list.size() % du;
		logger.info("count : {} " , count);
		List<Integer> tempResult = null;
		int size = 0;
		for (int i = 0; i < count; i++) {
			size = (i+1) * du;
			tempResult = list.subList(i * du, size > list.size() ? list.size() : size);
			logger.info("tempResult : {} " , tempResult);
		}
	}
	

    @Test
    public void sya2() {
        int num = 10, hash = 0;
        String key = "key1";
        hash = key.hashCode();
        logger.info("num : {} ,<< {} , << num : {}  , >> {} , >> num : {} , >>> : {} , >>> num : {} " ,this.toBinary(num) ,  this.toBinary(num << 1) , num << 1 , this.toBinary(num >> 1) , num >> 1 , this.toBinary(num >>> 16), num >>> 16);
//        logger.info("key1 二进制: {} , key.hashCode: {} , key.hashCode >>> 16: {} , hash() : {} , 二进制 hash(): {}   " , this.toBinary(hash) , hash , this.toBinary(hash >>> 16) , this.hash(key) , this.toBinary(this.hash(key)));
        this.hash(key);
        logger.info(" 24_b: {}, 45_b: {} , num_b: {} , num & : {} " , this.toBinary(24), this.toBinary(25), this.toBinary(24 & 45) , 24 & 45);
        logger.info("% {} , / {}", 11 % 2 , 11 / 2);
        logger.info(" ^ : {}", 2 ^ 3);
        logger.info(" 2二进制: {} " , Integer.toBinaryString(10));
        logger.info(" 2二进制: {} " , this.toBinary(11));
    }

    private String toBinary(int num) {

        StringBuffer sb = new StringBuffer();
        while (num != 0) {
            sb.append(num % 2);
            num = num / 2;
        }
        return sb.reverse().toString();
    }

    private String toBinary(String value) {
        int num = new Integer(value);
        StringBuffer sb = new StringBuffer();
        while (num != 0) {
            sb.append(num % 2);
            num = num / 2;
        }
        return sb.reverse().toString();
    }

    private int hash(Object key) {
        int h = key.hashCode();
        int result = h ^ (h>>> 16);
        logger.info(" hash: {} , h >>> 16: {} , hash_binary: {} , >>>_binary : {} , result: {} , result_binary : {} " , h , h >>> 16 , this.toBinary(h) , this.toBinary(h >>> 16) , result, this.toBinary(result));
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }

    @Test
    public void hashMapTest() {
        HashMap<String,String> map = Maps.newHashMap();
        map.put("key", "key1");
        map.put("key1", "key1");
        map.put("key", "key1");
    }
}
